﻿//OrderGrid.xaml.cs
//Copyright (c) 2013 StockSharp LLC, all rights reserved.
//This code module is part of StockSharp library.
//This code is licensed under the GNU GENERAL PUBLIC LICENSE Version 3.
//See the file License.txt for the license details.
//More info on: http://stocksharp.com

namespace StockSharp.Xaml
{
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Windows.Controls;

	using Ecng.Common;
	using Ecng.Xaml;

	using StockSharp.BusinessEntities;

	/// <summary>
	/// Визуальный контрол-таблица, отображающая заявки (коллекцию объектов класса <see cref="Order"/>).
	/// </summary>
	public partial class OrderGrid
	{
		/// <summary>
		/// Создать объект класса <see cref="OrderGrid"/>.
		/// </summary>
		public OrderGrid()
		{
			InitializeComponent();
			_orders.ItemsSource = new ThreadSafeObservableCollection<Order>();
		}

		/// <summary>
		/// Коллекция заявок, которые необходимо отобразить.
		/// </summary>
		public IList<Order> Orders
		{
			get { return (IList<Order>)_orders.ItemsSource; }
		}

		/// <summary>
		/// Выбранная заявка.
		/// </summary>
		public Order SelectedOrder
		{
			get
			{
				return SelectedOrders.FirstOrDefault();
			}
		}

		/// <summary>
		/// Выбранный заявки.
		/// </summary>
		public IEnumerable<Order> SelectedOrders
		{
			get
			{
				return _orders.SelectedItems.Cast<Order>();
			}
		}

		/// <summary>
		/// Происходит при новом выделении заявки.
		/// </summary>
		public event EventHandler<EventArgs> OrderSelected;

		private void OrdersSelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			OrderSelected.SafeInvoke(this);
		}
	}
}